#ifndef SERVER_H
#define SERVER_H

#include <QWidget>
#include <QHttpServer>
#include <QWebSocketServer>
#include <QProtobufSerializer>
#include "../chatClientPlus/model/data.h"
class HttpServer : public QObject
{
    Q_OBJECT
public:
    static HttpServer* getInstance();
    bool init();

    /////////////////////////////////////
    ////业务服务
    /////////////////////////////////////


    //获取个人信息
    QHttpServerResponse getUserInfo(const QHttpServerRequest &req);
    QHttpServerResponse getFriendList(const QHttpServerRequest &req);
    QHttpServerResponse getSessionList(const QHttpServerRequest &req);
    QHttpServerResponse getApplyList(const QHttpServerRequest &req);
    QHttpServerResponse getRecentMessageList(const QHttpServerRequest &req);
    QHttpServerResponse newMessage(const QHttpServerRequest &req);
    QHttpServerResponse setNickname(const QHttpServerRequest &req);
    QHttpServerResponse setDesc(const QHttpServerRequest &req);
    QHttpServerResponse getVertifyCode(const QHttpServerRequest &req);
    QHttpServerResponse setPhone(const QHttpServerRequest &req);
    QHttpServerResponse setAvatar(const QHttpServerRequest &req);
    QHttpServerResponse deleteFriend(const QHttpServerRequest &req);
    QHttpServerResponse sendApply(const QHttpServerRequest &req);
    QHttpServerResponse processsApply(const QHttpServerRequest &req);
    QHttpServerResponse searchUser(const QHttpServerRequest &req);
    QHttpServerResponse createSession(const QHttpServerRequest &req);
    QHttpServerResponse getSessionMemberList(const QHttpServerRequest &req);
    QHttpServerResponse searchMessage(const QHttpServerRequest &req);
    QHttpServerResponse searchMessageByTime(const QHttpServerRequest &req);
    QHttpServerResponse userLogin(const QHttpServerRequest &req);
    QHttpServerResponse userRegister(const QHttpServerRequest &req);
    QHttpServerResponse phoneLogin(const QHttpServerRequest &req);
    QHttpServerResponse phoneRegister(const QHttpServerRequest &req);
    QHttpServerResponse getSingleFile(const QHttpServerRequest &req);


private:
    HttpServer(){};
    HttpServer(const HttpServer&){};
    static HttpServer* instance;

    QHttpServer httpServer;
    QProtobufSerializer serializer;
signals:
};

class WebSocketServer:public QObject
{
    Q_OBJECT

public:
    static WebSocketServer* getInstance();
    bool init();

private:
    WebSocketServer():webSocketServer("websocket server",QWebSocketServer::NonSecureMode){};
    static WebSocketServer* instance;

    QWebSocketServer webSocketServer;
    QProtobufSerializer serializer;
signals:
    void sendTextNotify();
    void sendImageNotify();
    void sendFileNotify();
    void sendSpeechNotify();
    void sendFriendAddApplyNotify();
    void sendFriendAddApplyProcessNotify(bool isAgree);
    void sendCreateSessionNotify(bool isGroup);
};

#endif // SERVER_H
